package com.mobiporter.adias.tags;

import javax.servlet.jsp.JspException;
import com.mobiporter.adias.core.Manager;
import com.mobiporter.adias.tags.model.DetailUnitModel;
import com.mobiporter.adias.tags.model.LabeledComponentModel;
import com.mobiporter.adias.tags.utils.HTMLTagGenerator;


/**
 * A tag to render a heading, an icon,
 * description, and LabeledComponent.
 * 
 * @author Chetan Kumar
 *
 */
public class DetailUnit extends MobiTag
{

	private String headerClass ;
	private String descriptionClass ;
	private String propertiesClass ;
	
	private DetailUnitModel value ;
	
	private static final long serialVersionUID = 7469341127234358804L;

	@Override
	public void setValueToControl(String value) 
	{
		
	}

	@Override
	public int doEndTag() throws JspException 
	{
		return EVAL_PAGE ;
	}

	@Override
	public int doStartTag() throws JspException 
	{
		String html = HTMLTagGenerator.getDiv(value.getHeading(), getHeaderClass())
					+ HTMLTagGenerator.getDiv(value.getDescription(), getDescriptionClass());
		
		if (Manager.hasTableSupport(getUserAgent()))
		{
			html += HTMLTagGenerator.getTabledLabels(getValue().getProperties(),getPropertiesClass());
		}
		else	
		{
			for (LabeledComponentModel label : getValue().getProperties())
			{
				html += HTMLTagGenerator.getDiv(label.getText() + ":" + label.getValue(), getPropertiesClass());
			}
		}
		writeOut(html);
		
		return EVAL_BODY_INCLUDE;
	}

	public String getHeaderClass() {
		return headerClass;
	}

	public void setHeaderClass(String headerClass) {
		this.headerClass = headerClass;
	}

	public DetailUnitModel getValue() {
		return value;
	}

	public void setValue(DetailUnitModel value) {
		this.value = value;
	}

	public String getDescriptionClass() {
		return descriptionClass;
	}

	public void setDescriptionClass(String descriptionClass) {
		this.descriptionClass = descriptionClass;
	}

	public String getPropertiesClass() {
		return propertiesClass;
	}

	public void setPropertiesClass(String propertiesClass) {
		this.propertiesClass = propertiesClass;
	}
}
